﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinFu.AOP.Interfaces;
using LinFu.IoC.Interfaces;

namespace CoreEx.Services
{
    public class ServiceContainerInvokeWrapper : IServiceContainer
    {
        private IServiceContainer _serviceContainer;



        public ServiceContainerInvokeWrapper(IServiceContainer serviceContainer)
        {
            _serviceContainer = serviceContainer;
        }


        public void AddFactory(Type serviceType, IEnumerable<Type> additionalParameterTypes, IFactory factory)
        {
            _serviceContainer.AddFactory(serviceType,additionalParameterTypes,factory);
        }

        public bool Contains(Type serviceType, IEnumerable<Type> additionalParameterTypes)
        {
            return _serviceContainer.Contains(serviceType, additionalParameterTypes);
        }

        public object GetService(Type serviceType, params object[] additionalArguments)
        {
            lock(_serviceContainer)
            {
                return _serviceContainer.GetService(serviceType, additionalArguments);
            }
        }

        public IEnumerable<IServiceInfo> AvailableServices
        {
            get 
            {
                return _serviceContainer.AvailableServices;
            }
        }

        public bool SuppressErrors
        {
            get { return _serviceContainer.SuppressErrors; }
            set { _serviceContainer.SuppressErrors = value; }
        }

        public void AddFactory(string serviceName, Type serviceType, IEnumerable<Type> additionalParameterTypes, IFactory factory)
        {
            _serviceContainer.AddFactory(serviceName,serviceType,additionalParameterTypes,factory);
        }

        public bool Contains(string serviceName, Type serviceType, IEnumerable<Type> additionalParameterTypes)
        {
            return _serviceContainer.Contains(serviceName, serviceType, additionalParameterTypes);
        }

        public object GetService(string serviceName, Type serviceType, params object[] additionalArguments)
        {
            lock(_serviceContainer)
            {
                return _serviceContainer.GetService(serviceName, serviceType, additionalArguments);
            }
        }

        public IList<IPreProcessor> PreProcessors
        {
            get { return _serviceContainer.PreProcessors; }
        }

        public IList<IPostProcessor> PostProcessors
        {
            get { return _serviceContainer.PostProcessors; }
        }
    }
}
